import CounterStore from './modules/counter';
import UserStore from './modules/user'
import { createContext , useContext } from 'react';


// export const RootStore1 =()=> useContext(createContext({
//   counter:new CounterStore(),
//   user:new UserStore()
// }))

export default class RootStore {
  constructor() {
    this.counter = new CounterStore();
    this.user = new UserStore();
  }
  // You can add more stores here as needed
}


const RooteContext = createContext();
export const RootStoreProvider = ({ children }) => {
  const store = new RootStore();
  return (
    <RooteContext.Provider value={store}>
      {children}
    </RooteContext.Provider>
  );
};

export const useRootStore = () => {
  const context = useContext(RooteContext);
  if (!context) {
    throw new Error('useRootStore must be used within a RootStoreProvider');
  }
  return context;
}